/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 * ***************************************************************************/


#include "stdafx.h"
#include <pgl/core/PGLLine1D.h>
#include <pgl/core/PGLDataVectors.h>
#include <pgl/core/DataRegistry.h>

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

PGL_IMPLEMENT_DYNCREATE(CPGLLine1D, CPGLLine);

void CPGLLine1D::SerializeXML(CPGLArchive& ar)
{
	CString strPos;	strPos.Format(_T("%u"),(DWORD)this);
	static const TCHAR szTag[] = _T("CPGLLine1D");

	markup::CMarkupArchive& xml = *((markup::CMarkupArchive*)ar.GetMarkup());
	if(ar.IsStoring())
	{
		xml.AddChildElem(szTag);
		xml.AddChildAttrib(_T("Name"),GetName());
		xml.IntoElem();

			/////////////////////////////////////////////////////////
			// Adding base class
			CPGLLine::SerializeXML(ar);
			xml.AddChildElem(_T("Values"));
			xml.IntoElem();
				m_pValues->SerializeXML(ar);
			xml.OutOfElem();
				
		xml.OutOfElem();
	}
	else
	{
		if  (!xml.FindChildElem(szTag))
				return;



		xml.IntoElem();
			CPGLLine::SerializeXML(ar);

			PGL_SERIALIZE_LOAD_DATA( strPos , Values , m_pValues );

		xml.OutOfElem();
	}
}


#ifdef _DEBUG
void CPGLLine1D::Dump( CDumpContext& dc ) const
{
    // call base class function first
    CPGLLine::Dump( dc );
}
void CPGLLine1D::AssertValid() const
{
    // call inherited AssertValid first
    CPGLLine::AssertValid();

} 
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CPGLLine1D::CPGLLine1D(const CPGLColor& _FrontColor, const CPGLColor& _FillColor,EInterpolationType  _eInterpolationType, EMarkerType _eMarkerType, LPCTSTR _szDashPattern)
: CPGLLine(_FrontColor,_FillColor,_eInterpolationType, _eMarkerType, _szDashPattern)
{

}

CPGLLine1D& CPGLLine1D::operator =(const CPGLLine1D& l)
{
	if (this != &l)
	{
		this->CPGLLine::operator =(l);
		
		ClearData();

		m_pValues = l.m_pValues->Clone();
	}
	return *this;
}

CPGLLine1D::~CPGLLine1D()
{
	m_pValues.reset();
}

void CPGLLine1D::SetValues(const std::vector<double>& vValues, bool bMakeOwnCopy)
{
	if (bMakeOwnCopy)
	{
		SetValues(CPGLVectorDPtr(new CPGLVectorD(vValues)));
	}
	else
	{
		SetValues(CPGLVectorRefDPtr(new CPGLVectorRefD(vValues)));
	}
}

void CPGLLine1D::SetValues(const std::vector<float>& vValues, bool bMakeOwnCopy)
{
	if (bMakeOwnCopy)
	{
		SetValues(CPGLVectorFPtr(new CPGLVectorF(vValues)));
	}
	else
	{
		SetValues(CPGLVectorRefFPtr(new CPGLVectorRefF(vValues)));
	}
}
void CPGLLine1D::SetValues(const std::vector<int>& vValues, bool bMakeOwnCopy)
{
	if (bMakeOwnCopy)
	{
		SetValues(CPGLVectorIPtr(new CPGLVectorI(vValues)));
	}
	else
	{
		SetValues(CPGLVectorRefIPtr(new CPGLVectorRefI(vValues)));
	}
}
void CPGLLine1D::SetValues(const std::vector<BYTE>& vValues, bool bMakeOwnCopy)
{
	if (bMakeOwnCopy)
	{
		SetValues(CPGLVectorBPtr(new CPGLVectorB(vValues)));
	}
	else
	{
		SetValues(CPGLVectorRefBPtr(new CPGLVectorRefB(vValues)));
	}
}

void CPGLLine1D::SetValues( CPGLDataPtr pValues )
{
	ClearData();

	m_pValues = pValues;
}

void CPGLLine1D::ClearData()
{
	m_pValues.reset();
}
